<template>
	<view class="content">
		
		<view class="onelineView">
			
			<view class="leftHint">我的团队:</view>
			
			<input class="inputView" v-model="myteam" @focus="showView(1)" placeholder="请选择团队"></input>
			
			<image class="updownImage" :src="showViewStatus==1?image2:image1"  @click="close(1)"></image>
			
			
			<view class="showtableView" v-if="showViewStatus==1">
				
				
				<!-- <view class="leftHint">我的团队:</view> -->
				
				
				<view   v-for="(item,index) in teamList" :key='index'>
					
					<view class="teamView2"  :style="{color:selectTeam.id== item.id?'#FF0000':'#333333'}" @click="teamSelect(index)">{{item.name}}</view>
					
					
					<view style="width: 100%;height: 2upx;background: #eeeeee;"></view>
					
					
					
				</view>
				
			
				
				
				<!-- selectTeam -->
				
				
			</view>
			
		</view>
		
		
		
		<view class="onelineView">
			
			<view class="leftHint">复投商品:</view>
			
			<input class="inputView" v-model="mygoods" @focus="showView(2)" placeholder="请选择商品"></input>
			
			<image class="updownImage" :src="showViewStatus==2?image2:image1"  @click="close(2)"></image>
			
			
			
			<view class="showtableView" v-if="showViewStatus==2">
				
				<view   v-for="(item,index) in prolist" :key='index'>
					
					<view :style="{color:selectGoods.id== item.id?'#FF0000':'#333333'}" class="teamView2" @click="goddsSelect(index)">{{item.name}}</view>
					
					
					<view style="width: 100%;height: 2upx;background: #eeeeee;"></view>
					
					
					
				</view>
				
				
			</view>
			
		</view>
		
		
		
		<view class="onelineView">
			
			<view class="leftHint">商品数量:</view>
			
			<input type="number" :maxlength="4" class="inputView" v-model="mynums" placeholder="请输入商品数量"></input>
			

			
		</view>
		
		
		<view class="cell-group margin-cell-group" v-if="userShip && userShip.id" @click="goAddress">
			<view class="cell-item add-title-item right-img cell-item-mid">
				<view class="cell-item-hd">
					<image class="cell-hd-icon" src="/static/image/location.png"></image>
				</view>
				<view class="cell-item-bd cell-item-bd-block">
					<view class="cell-bd-view">
						<text class="cell-bd-text">收货人：{{ userShip.name || '' }}</text>
						<text class="cell-bd-text-right">{{ userShip.mobile || '' }}</text>
					</view>
					<view class="cell-bd-view">
						<text class="cell-bd-text address">{{ userShip.area_name || '' }} {{ userShip.address || '' }}</text>
					</view>
				</view>
				<view class="cell-item-ft">
					<image class="cell-ft-next icon" src="/static/image/right.png"></image>
				</view>
			</view>
		</view>
		<view class="cell-group margin-cell-group" v-else>
			<view class="cell-item add-title-items"><button class="btn btn-b" @click="goAddress()" hover-class="btn-hover2">添加收货地址</button></view>
		</view>
		
		

		<view class="button-bottom">

			<view class="bottomButton" @click="toAdd()">{{isadd==0?'新增产品':'修改产品'}}</view>
		</view>
	</view>
</template>

<script>
export default {
    data() {
        return {
			prolist: [] ,// 用户收货地址列表
			teamList : [],
			type: '',
			myteam : '',
			mygoods : '',
			mynums : '',
			showViewStatus: 0,
			image1 : '/static/image/my/arrowup.png',
			image2 : '/static/image/my/arrowdown.png',
			selectTeam : '',
			selectGoods : '',
			userShip : '',
			isadd : 0,
			
			oldteamid : '',
			
			modifyid : '',
			
			oldgoodid : '',
			
        }
    },
	onLoad (e) {
	
		
		
		if (e.teamid){
			
			console.log(222);
			
			// console.log(e.goodid);
			
			this.isadd = 1;
			
			this.mynums = e.goodnum;
			
			this.userShip = e.addinfo;
			
	
			
			this.oldteamid = e.teamid;
			
			this.oldgoodid = e.goodid;
			
			
			this.modifyid = e.id;
			
			// console.log(this.modifyid);
			
			
			// var show = './addReselectGood?teamid=' + info.team_type
			//  + '&goodid=' + info.goods_id + '&goodnum=' + info.goods_num ;
			 
			//  if (info.user_ship_data){
			// 	 show = show + '&addinfo=' + info.user_ship_data ; 
			//  }
			 
			
		}
	
		// console.log(e);
	
	},
	onShow () {
		

		
		let user_ship = this.$db.get('address_user_ship', true);
		
		console.log(user_ship);
		
		if (user_ship) {
			
	
			
			this.userShip = user_ship;
			// this.params.area_id = user_ship.area_id;
			this.$db.del('address_user_ship', true);
				
		}
		
		if(this.$store.state.shopAddress.id) {
			this.store = this.$store.state.shopAddress
		}
		
		
		// console.log(this.userShip);
		
		
		this.getgoodslist();

	},
    methods: {
		// 获取收货地址列表
		getgoodslist () {
		
	
			var data = {
				is_declar : 1,
				fenqu_id : 1,
				limit : 10000,
			}
		
			this.$api.goodsList( data, res => {
				if (res.status) {
					console.log(res);
					this.prolist = res.data.list;
		
					
					this.getteamlist();	
				}
			})

		},
		
		// 没有收货地址时跳转
		goAddress() {
			uni.navigateTo({
				url: '/pages/member/address/list?type=order'
			});
		},
		

		
		close(op){
			
			// this.showViewStatus = 0;
			
			
			if (this.showViewStatus == 0){
				
				if (op == 1){
					
					this.showViewStatus = 1;
					
				}else{
					
					
					
					this.showViewStatus = 2;
					
				}
				
				
			}else{
				this.showViewStatus = 0;
			}
			
		
			
			
		},
		
		
		getteamlist () {
		
			
	
		
			this.$api.teamtype( {}, res => {
				if (res.status) {
			
					this.teamList = res.data;
					
					this.configSelection();
				
					console.log(this.teamList );
				
				}
			})
		
		},
		
		
		
		configSelection(){
		
		
			console.log(this.oldgoodid);
			
			console.log(this.prolist);
			
			
		
			if (this.prolist && this.oldgoodid){
				
				for (var i=0;i<this.prolist.length;i++){
					
					console.log(this.prolist[i].id )
					
					if (this.prolist[i].id == this.oldgoodid){
						
						this.selectGoods = this.prolist[i];
						
							// console.log(this.selectGoods);
						
						this.mygoods = this.selectGoods.name;
						
						break;
						
					}
					
					
				}
				
				
				
			}
	
			
			if (this.teamList && this.oldteamid){
				
				for (var i=0;i<this.teamList.length;i++){
					
					console.log(this.teamList[i].id )
					
					if (this.teamList[i].id == this.oldteamid){
						
						this.selectTeam = this.teamList[i];
						
						// console.log(this.selectGoods);
						
						this.myteam = this.selectTeam.name;
						
						break;
						
					}
					
					
				}
				
				
				
			}
				
			
			
		},
		
		
		showView(op){
			
			if (op == 1){
				
				this.showViewStatus = 1;
				
			}else{
				
				
				
				this.showViewStatus = 2;
				
			}
			
			console.log(this.showViewStatus )
			
		},
		
		goddsSelect(op){
			
			console.log(op);
			
			this.selectGoods = this.prolist[op];
			
				console.log(this.selectGoods);
			
			this.mygoods = this.selectGoods.name;
			
			
			this.showViewStatus = 0;
			
			
				// console.log(this.myteam.name);
			
		},
		
		teamSelect(op){
			
			console.log(op);
			
			this.selectTeam = this.teamList[op];
			
			this.myteam = this.selectTeam.name;
			
			
			this.showViewStatus = 0;
			
			
				// console.log(this.myteam.name);
			
		},
			
			
		toAdd(){
			
			
			
			if (!this.selectTeam) {
				this.$common.errorToShow('请选择团队');
				return;
			}else if (!this.selectGoods) {
				this.$common.errorToShow('请选择商品');
				return;
			}else if (!this.mynums)
			{
				this.$common.errorToShow('请输入商品数量');
				return;
			}
			
			
			
			// myteam : '',
			// mygoods : '',
			// mynums : '',
			// showViewStatus: 0,
			// image1 : '/static/image/my/arrowup.png',
			// image2 : '/static/image/my/arrowdown.png',
			// selectTeam : '',
			// selectGoods : '',
			
			var token = this.$db.get('userToken');
			
				let data = {
					team_type : this.selectTeam.id,
					goods_id: this.selectGoods.id,
					goods_num: this.mynums,
					token : token ,
		
				};

				if (this.modifyid){
					
					data['id'] = this.modifyid;
					
				}
			
				if (this.userShip){
					
					data['user_ship_id'] = this.userShip.id;
					
				}
				
				
				console.log(data);
				
				
				
				// return;
				
				if (this.isadd==0){
					
					this.$api.adduserrepeatgoods(data, res => {
							if (res.status) {
					uni.navigateBack({
						// delta: 1
					});
							} else {
								this.$common.errorToShow(res.msg);
							}
						});
					
				}else{
					
					this.$api.edituserrepeatgoods(data, res => {
							if (res.status) {
					uni.navigateBack({
						// delta: 1
					});
							} else {
								this.$common.errorToShow(res.msg);
							}
						});
					
					
				}
				
				
			

			
			
			
			
		
			
			
		}
	

    }
}
</script>

<style>

.onelineView{
	
	position: relative;
	
	margin-top: 30upx;
	
	background: #FFFFFF;
	
	width: 100%;
	
	height: 90upx;
	
	display: flex;
	
	flex-direction: row;
	
	align-items: center;
	
	
}

.leftHint{
	
	width: 20%;
	
	height: 100%;
	
	line-height: 90upx;
	
	color: #FF0000;
	
	text-align: right;
	
	font-size: 28upx;
	
	
	
	
}


.teamView{
	
	
	width: 400upx;
	
	line-height: 100upx;
	
	text-align: center;
	
	color: #333333;
	
	height: 100upx;
	
	
	
	
}


.teamView2{
	
	
	width: 550upx;
	
	line-height: 100upx;
	
	text-align: center;
	
	color: #333333;
	
	height: 100upx;
	
	
	
}



.showtableView{
	
	position: absolute;
	
	left: 22%;
	
	top: 90upx;
	
	border-color: #666666;
	
	border-width: 1upx;
	
	border-style: solid;
	
	
	
	
/* 	left: 0;
	
	top: 0; */
	
	
/* 	width: 60%;
	
	height: 300upx; */
	
	background: #FFFFFF;
	
	
	z-index: 9999;
	
	
}

.inputView{
	
	font-size: 28upx;
	
	
	
	
	margin-left: 30upx;
	
	
	
}


.bottomButton{
	
	line-height: 90upx;
	
	width: 100%;
	
	height: 100%;
	
	text-align: center;
	
	color: #FFFFFF;

	background: #000000;
	
}

.updownImage{
	
	/* background: #00BFFF; */
	
	width: 30upx;
	
	height: 30upx;
	
}


</style>